$(function(){
	var firstdepart = $('.first-depart'),
		seconddepart = $('.second-depart'),
		firstForm = $('#first-depart'),
		secondForm = $('#second-depart'),
		imgModal = $('#imgModal');


	// 点编辑
	$('.editate').on('click',function(){
		var id = $(this).data('id');
		$('#eidateId').val(id);
		imgModal.removeClass('hide');
		firstdepart.removeClass('hide');
		seconddepart.addClass('hide');

		
	})

		// 联动

	$('body').on('mousedown','#neighborhood1 .option',function(){
		var id = $(this).data('value');
		var listr = '';
		$('#grid1').html(listr);
		$('#grid1').siblings('input').val('');


		$.ajax({
			url: '/Admin/User/getAllReseau',
			type:'post',
			dataType:'json',
			data:{id:id},
			success:function(json){
				console.log(json)
		        $.each(json,function(i,val){
		    		listr += '<div class="option" data-value="'+val.id+'" data-url=""><span>'+val.nbh_name+'</span></div>';
					$('#grid1').html(listr);
		        })
		        
		        
			},
			error:function(json){

			}
		})
	})
	// 提交
		firstForm.validate();
		firstForm.on('submit',function(){
			try {
				if (firstForm.valid()) {
					firstForm.submitForm();
				}

			}catch(e){
				console.log(e)
			}

			return false;
		})


	var firstTerrace = $('#firstTerrace'),
		neighborpower = $('#neighborpower'),
		neighborperson = $('#neighborperson'),
		firstPerson = $('#firstPerson'),
		secondPerson = $('#secondPerson'),
		threePerson = $('#threePerson'),
		first_k = $('.first-k'),
		second_k = $('.second-k');


	// 点权限
	$('.power').on('click',function(){
		var id = $(this).data('id');
		console.log(id)
		$('#powerId').val(id);
		imgModal.removeClass('hide');
		firstdepart.addClass('hide');
		seconddepart.removeClass('hide');
		threePerson.attr('name','');	
		// $('#power').val('2');

	})



	$('body').on('mousedown','#firstTerrace .option',function(){
		if (first_k.hasClass('selected')) {
			neighborpower.removeClass('hide');
			neighborperson.addClass('hide');

			firstPerson.attr('name','committee');
			secondPerson.attr('name','reseau');
			threePerson.attr('name','');
		}else{
			neighborpower.addClass('hide');
			neighborperson.removeClass('hide');

			threePerson.attr('name','committee');
			firstPerson.attr('name','');
			secondPerson.attr('name','');
		}
	})

	// 联动

	$('body').on('mousedown','#neighborhood .option',function(){
		var id = $(this).data('value');
		var listr = '';
		$('#grid').html(listr);
		$('#grid').siblings('input').val('');


		$.ajax({
			url: '/Admin/User/getAllReseau',
			type:'post',
			dataType:'json',
			data:{id:id},
			success:function(json){
		        $.each(json,function(i,val){
		    		listr += '<div class="option" data-value="'+val.id+'" data-url=""><span>'+val.nbh_name+'</span></div>';
					$('#grid').html(listr);
		        })
		        
		        
			},
			error:function(json){

			}
		})
	})

	// 提交
	secondForm.validate();
	secondForm.on('submit',function(){
		try {
			if (secondForm.valid()) {
				secondForm.submitForm();
			}

		}catch(e){
			console.log(e)
		}

		return false;
	})



	// 解冻

	$('.withdrawal').on('click',function(){
    var str = '确认解冻！';
    var id = $(this).data('id');
	    $.confirm({
	      msg:str,
	      confirm:function(){
		      $.ajax({
		          url:'/Admin/User/free',
		          type:'post',
		          data:{id:id},
		          dataType:'json',
		          success:function(json){
		            console.log(json)
		            if (json.code == 1) {
		              $.alert('解冻成功！');
		              window.location.reload();
		            }
		          },
		          error:function(json){

		          }
		        })
		    }
	    })
   })

	// 冻结

	$('.look').on('click',function(){
    var str = '确认冻结！';
    var id = $(this).data('id');
	    $.confirm({
	      msg:str,
	      confirm:function(){
		      $.ajax({
		          url:'/Admin/User/freeze',
		          type:'post',
		          data:{id:id},
		          dataType:'json',
		          success:function(json){
		            console.log(json)
		            if (json.code == 1) {
		              $.alert('冻结成功！');
		              window.location.reload();
		            }
		          },
		          error:function(json){

		          }
		        })
		    }
	    })
   })



	// 取消权限

	$('.cancelpower').on('click',function(){
    var str = '确认取消权限！';
    var id = $(this).data('id');
	    $.confirm({
	      msg:str,
	      confirm:function(){
		      $.ajax({
		          url:'/Admin/User/revoke',
		          type:'post',
		          data:{id:id},
		          dataType:'json',
		          success:function(json){
		            console.log(json)
		            if (json.code == 1) {
		              $.alert('取消权限成功！');
		              window.location.reload();
		            }
		          },
		          error:function(json){

		          }
		        })
		    }
	    })
   })
})